import java.util.HashMap;
import java.util.Map;
import java.util.Date;
import java.util.Scanner;
public class UserManagementSystem {
    private Map<String, User> users = new HashMap<>(); // 模拟用户数据存储
    // 注册新用户
    public boolean registerUser(String userId, String username, String password, String email, String phoneNumber,
                                String fullName, String address, String gender, Date birthDate) {
        if (users.containsKey(userId)) {
            System.out.println("Error: User ID already exists.");
            return false;
        }
        User newUser = new User(userId, username, password, email, phoneNumber, fullName, address, gender, birthDate);
        users.put(userId, newUser);
        System.out.println("User registered successfully.");
        return true;
    }
    // 用户登录验证
    public boolean loginUser(String userId, String password) {
        if (!users.containsKey(userId)) {
            System.out.println("Error: User ID does not exist.");
            return false;
        }
        User user = users.get(userId);
        if (user.getPassword().equals(password)) {
            System.out.println("Login successful. Welcome, " + user.getUsername() + "!");
            return true;
        } else {
            System.out.println("Error: Incorrect password.");
            return false;
        }
    }
    // 内部类，用于模拟用户
    private class User {
        private String userId;
        private String username;
        private String password;
        private String email;
        private String phoneNumber;
        private String fullName;
        private String address;
        private String gender;
        private Date birthDate;
        private Date registrationDate;
        public User(String userId, String username, String password, String email, String phoneNumber,
                    String fullName, String address, String gender, Date birthDate) {
            this.userId = userId;
            this.username = username;
            this.password = password;
            this.email = email;
            this.phoneNumber = phoneNumber;
            this.fullName = fullName;
            this.address = address;
            this.gender = gender;
            this.birthDate = birthDate;
            this.registrationDate = new Date(); // 当前日期作为注册日期
        }
        public String getUserId() {
            return userId;
        }
        public String getUsername() {
            return username;
        }
        public String getPassword() {
            return password;
        }
        public String getEmail() {
            return email;
        }
        public String getPhoneNumber() {
            return phoneNumber;
        }
        public String getFullName() {
            return fullName;
        }
        public String getAddress() {
            return address;
        }
        public String getGender() {
            return gender;
        }
        public Date getBirthDate() {
            return birthDate;
        }
        public Date getRegistrationDate() {
            return registrationDate;
        }
    }
    // 测试代码
    public static void main(String[] args) {
        UserManagementSystem system = new UserManagementSystem();
        Scanner scanner = new Scanner(System.in);
        // 获取用户输入信息
        System.out.println("Register a new user:");
        System.out.print("User ID: ");
        String userId = scanner.nextLine();
        System.out.print("Username: ");
        String username = scanner.nextLine();
        System.out.print("Password: ");
        String password = scanner.nextLine();
        System.out.print("Email: ");
        String email = scanner.nextLine();
        System.out.print("Phone Number: ");
        String phoneNumber = scanner.nextLine();
        System.out.print("Full Name: ");
        String fullName = scanner.nextLine();
        System.out.print("Address: ");
        String address = scanner.nextLine();
        System.out.print("Gender: ");
        String gender = scanner.nextLine();
        System.out.print("Birth Date (yyyy-mm-dd): ");
        String birthDateString = scanner.nextLine();
        Date birthDate = Date.valueOf(birthDateString); // 转换字符串为日期类型
        // 注册用户
        system.registerUser(userId, username, password, email, phoneNumber, fullName, address, gender, birthDate);
        // 登录用户
        System.out.println("\nLogin user:");
        System.out.print("User ID: ");
        String loginUserId = scanner.nextLine();
        
        System.out.print("Password: ");
        String loginPassword = scanner.nextLine();
        system.loginUser(loginUserId, loginPassword);
        scanner.close();
    }
}